import React, { createContext, useContext, useState, ReactNode } from "react";

interface processState {
  selectedAssetId: string;
  processName: string;
}

interface ProcessContextProps {
  processState: processState;
  setProcessState: (state: processState) => void;
}

const ProcessContext = createContext<ProcessContextProps | undefined>(
  undefined
);

export const ProcessProvider: React.FC<{ children: ReactNode }> = ({
  children,
}) => {
  const [processState, setProcessState] = useState<processState>({
    selectedAssetId: "",
    processName: "",
  });

  return (
    <ProcessContext.Provider value={{ processState, setProcessState }}>
      {children}
    </ProcessContext.Provider>
  );
};

export const useProcessContext = (): ProcessContextProps => {
  const context = useContext(ProcessContext);
  if (!context) {
    throw new Error("useProcessContext must be used within a ProcessProvider");
  }
  return context;
};
